package com.med.service.impl;

import com.med.entity.AppointmentDO;
import com.med.entity.MedicalRecordDO;
import com.med.entity.MedicineOrderDO;
import com.med.mapper.VisitMapper;
import com.med.service.IVisitService;
import com.med.vo.MedicalRecordVO;
import com.med.vo.MedicineOrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Project:internet-based-healthcare
 * Package:com.med.service.impl
 *
 * @Description:
 * @Author:其一
 * @CreateTime: 2025-08-23-13-45
 */
@Service
public class VisitServiceImpl implements IVisitService {
    @Autowired
    private VisitMapper visitMapper;

    @Override
    public List<MedicalRecordDO> selectMedicalRecord(Integer userId) {
        List<MedicalRecordDO> records = visitMapper.selectMedicalRecord(userId);
        // 打印日志，查看数据库查询的原始结果
        System.out.println("-----------");
        System.out.println("查询结果：" + records);
        System.out.println("-----------");
        return records;
    }

    @Override
    public List<AppointmentDO> selectUserMessage(String userName) {
        List<AppointmentDO> records=visitMapper.selectUserMessage(userName);
        System.out.println("查询结果：" + records);
        return records;
    }

    @Override
    public Integer insertMedicalRecord(MedicalRecordVO medicalRecordVO) {
        return visitMapper.insertMedicalRecord(medicalRecordVO);
    }

    @Override
    public Integer createMedicineOrder(MedicineOrderVO medicineOrderVO) {
        Integer res = visitMapper.createMedicineOrder(medicineOrderVO);
        List<MedicineOrderDO> orderList = visitMapper.queryOrderId(medicineOrderVO);
        Integer medicineOrderId = orderList.get(0).getMedicineOrderId();
        medicineOrderVO.setMedicineOrderId(medicineOrderId);
        System.out.println("获取的订单ID: " + medicineOrderId);
        if(res==1){
            visitMapper.createMediciOrderDatil(medicineOrderVO);
        }
        return res;
    }
}
